<?php
namespace app\common\controller;
use think\Loader;
use think\Controller;
use think\Session;
use think\Db;
class Frontend extends Controller
{
    protected function _initialize()
    {
        $adminhost =Db::name('Config')->where('name','memberHost')->value('value');
        if(!empty($adminhost)){
            $host = $this->request->host(true);
            if($host !== $adminhost){
                die('访问限制');
            }
        }
        $this->assign('memberNotice',Db::name('Config')->where('name','memberNotice')->value('value'));
        $modulename = $this->request->module();
        $controllername = Loader::parseName($this->request->controller());
        $actionname = strtolower($this->request->action());
        $path = str_replace('.', '/', $controllername) . '/' . $actionname;
        //检测是否登录
        if (!Session::get('spadminUser') && $path != 'login/index') {
            $url = Session::get('referer');
            $this->redirect('Login/index');
            exit();
        }else{
            if($path == 'login/index' && Session::get('spadminUser')){
                $url = Session::get('referer');
                $this->redirect('index/index');
            }
            if(Session::get('spadminUser')){
                $url = $this->request->url();
                $domain = Db::name('Domain')->where('user_id',Session::get('spadminUser')['id'])->where('status',1)->select();
                $this->assign('domain',$domain);
                $this->assign('url',$url);
            }
        }
        
    }

}